package config

import (
	"github.com/go-kratos/kratos/v2/log"
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type Config struct {
	Data struct {
		Database struct {
			Driver string `yaml:"driver"`
			Source string `yaml:"source"`
		} `yaml:"database"`
	} `yaml:"data"`
}

func LoadConfig(path string) (*Config, error) {
	var cfg Config
	data, err := ioutil.ReadFile(path)
	if err != nil {
		log.Fatalf("error reading file: %v", err)
	}
	err = yaml.Unmarshal(data, &cfg)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	return &cfg, nil
}
